/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import merlion.crm.slcm.entity.Address;
import merlion.frm.bpm.entity.SupplierInvoice;

/**
 *
 * @author Yuwei
 */
@Entity
public class Supplier implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String supplierName;
    private String supplierId;
    private Double rating;
    private Double actualLeadTime;
    @OneToMany(targetEntity=RawMaterialSupplyInformation.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
    private List<RawMaterialSupplyInformation> rawMaterialsSupplied;
    @OneToOne(targetEntity=Address.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Address supplierAddress;
    @OneToMany(targetEntity=SupplierContactRecord.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
    private List<SupplierContactRecord> contacts;
    @OneToMany(targetEntity=RawMaterialPurchaseOrder.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, mappedBy="supplier")
    private List<RawMaterialPurchaseOrder> rmpos;
    @OneToMany(targetEntity=RawMaterialSalesOrder.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, mappedBy="supplier")
    private List<RawMaterialSalesOrder> rmsos;
    @OneToMany(targetEntity=SupplierInvoice.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, mappedBy="supplier")
    private List<SupplierInvoice> invoices;
    @OneToMany(targetEntity=GoodsReceipt.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, mappedBy="supplier")
    private List<GoodsReceipt> receipts;

    public Supplier(){
        supplierName = "";
        supplierId = "";
        rawMaterialsSupplied = new ArrayList<RawMaterialSupplyInformation>();
        supplierAddress = new Address();
        contacts = new ArrayList<SupplierContactRecord>();
        rmpos = new ArrayList<RawMaterialPurchaseOrder>();
        rmsos = new ArrayList<RawMaterialSalesOrder>();
        invoices = new ArrayList<SupplierInvoice>();
        rating = 0.0D;
        actualLeadTime = 0.0D;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<GoodsReceipt> getReceipts() {
        return receipts;
    }

    public void setReceipts(List<GoodsReceipt> receipts) {
        this.receipts = receipts;
    }

    public String getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(String supplierId) {
        this.supplierId = supplierId;
    }

    public Collection<RawMaterialSupplyInformation> getRawMaterialsSupplied() {
        return rawMaterialsSupplied;
    }

    public void setRawMaterialsSupplied(List<RawMaterialSupplyInformation> rawMaterialsSupplied) {
        this.rawMaterialsSupplied = rawMaterialsSupplied;
    }

    public Address getSupplierAddress() {
        return supplierAddress;
    }

    public void setSupplierAddress(Address supplierAddress) {
        this.supplierAddress = supplierAddress;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public List<SupplierContactRecord> getContacts() {
        return contacts;
    }

    public void setContacts(List<SupplierContactRecord> contacts) {
        this.contacts = contacts;
    }

    public List<SupplierInvoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(List<SupplierInvoice> invoices) {
        this.invoices = invoices;
    }

    public List<RawMaterialPurchaseOrder> getRmpos() {
        return rmpos;
    }

    public void setRmpos(List<RawMaterialPurchaseOrder> rmpos) {
        this.rmpos = rmpos;
    }

    public List<RawMaterialSalesOrder> getRmsos() {
        return rmsos;
    }

    public void setRmsos(List<RawMaterialSalesOrder> rmsos) {
        this.rmsos = rmsos;
    }

    public Double getRating() {
        return rating;
    }

    public void setRating(Double rating) {
        this.rating = rating;
    }

    public Double getActualLeadTime() {
        return actualLeadTime;
    }

    public void setActualLeadTime(Double actualLeadTime) {
        this.actualLeadTime = actualLeadTime;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Supplier)) {
            return false;
        }
        Supplier other = (Supplier) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.Supplier[ id=" + id + " ]";
    }
    
}
